package com.hippo.javacore.javaiostream.iostream;

import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * @ClassName InputStreamReaderOpt
 * @Description TODO 字符输入转换流操作类
 * @Author tangxl
 * @create 2023-04-07 08:37
 **/
public class InputStreamReaderOpt {
    public static void main(String[] args) {
        // 字符输入转换流, 读取文件时，需要指定编码表，否则会出现乱码
        try (
                // 创建字符输入转换流对象，指定编码表(`utf-8`, `gbk`, `gb2312`)
                InputStreamReader isr = new InputStreamReader(new FileInputStream("study-commons/java-file-iostream/src/main/resources/file/a.txt"), "GBK");
                ){
            int len = 0;
            char[] chs = new char[1024];
            while ((len = isr.read(chs)) != -1) {
                System.out.print(new String(chs, 0, len));
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
